home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10578 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  72 lines

  1. Newsgroups: comp.lang.c
  2. Path: coral.indstate.edu!kalliank
  3. From: kalliank@coral.indstate.edu
  4. Subject: Re: while loop problem
  5. Message-ID: <kalliank.1.314DC1C0@coral.indstate.edu>
  6. Sender: news@onyx.indstate.edu
  7. Nntp-Posting-Host: 139.102.86.46
  8. Organization: Indiana State University
  9. References: <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca>
  10. Date: Mon, 18 Mar 1996 20:04:16 GMT
  11.  
  12. In article <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca> Bill Simpson <wsimpson@uwinnipeg.ca> writes:
  13. >Path: onyx.indstate.edu!usenet.ucs.indiana.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!newsfeed.internetmci.com!solaris.cc.vt.edu!news.mathworks.com!uhog.mit.edu!uw-beaver!nntp.cs.ubc.ca!unixg.ubc.ca!news.bc.net!rover.ucs.ualberta.ca!tribune.usask.ca!m
  14. >ngol.sasknet.sk.ca!canopus.cc.umanitoba.ca!io.UWinnipeg.ca!wsimpson
  15. >From: Bill Simpson <wsimpson@uwinnipeg.ca>
  16. >Newsgroups: comp.lang.c
  17. >Subject: while loop problem
  18. >Date: Tue, 12 Mar 1996 13:36:41 -0600
  19. >Organization: The University of Manitoba
  20. >Lines: 33
  21. >Message-ID: <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca>
  22. >NNTP-Posting-Host: io.uwinnipeg.ca
  23. >Mime-Version: 1.0
  24. >Content-Type: TEXT/PLAIN; charset=US-ASCII
  25.  
  26.  
  27. >Consider the following code fragment:
  28.  
  29. >y=2000; z=1000;
  30. >x=0;
  31. >while(x<=XMAX)
  32. >        {
  33. >        x+=(int) erand(mean);
  34. >        setdot(x,y,z);
  35. >        }
  36. >        
  37. >It plots a line of dots that are randomly (exponentially) spaced, giving
  38. >a 1D spatial Poisson process.
  39. >The problem is that dot x coordinates can only be between 0 and XMAX.
  40. >The above code will also attempt to plot one point at an x value >XMAX
  41. >before it terminates.
  42.  
  43. >Is there a nice way to write the code so it works properly?
  44.  
  45. >The only way I have thought of is
  46. >y=2000; z=1000;
  47. >x=0;
  48. >while(x<=XMAX)
  49. >        {
  50. >        x+=(int) erand(mean);
  51. >        if(x<=XMAX)
  52. >                setdot(x,y,z);
  53. >        }
  54.  
  55. >which seems very clumsy since the same test is done twice.
  56.  
  57. >Thanks very much for any help.
  58.  
  59. >Bill Simpson
  60.  
  61. Is This Any Better :-
  62.  
  63. y=2000; z=1000;
  64. x=(int) erand(mean);
  65.  
  66. while(x <= XMAX)
  67.   {
  68.    setdot(x,y,z);
  69.    x += (int) erand(mean);
  70.   }
  71.                         Keshav..
  72.